<template>
  <view class="content">
    <view class="user-info-section">
      <image
        v-if="userInfo.avatar"
        class="portrait"
        mode="aspectFill"
        :src="userInfo.avatar"
      ></image>
      <image
        v-else
        class="portrait"
        mode="aspectFill"
        src="../../static/icons/user.png"
      ></image>
      <view class="info-section" @click="switchPage('/pages/user/user-edit')">
        <view class="nickname">{{ userInfo.nickName }}</view>
        <view class="info">我的信息</view>
      </view>
    </view>
    <view class="divider divider2"> 我的订单 </view>
    <div class="order-section">
      <div class="top">
        <div
          class="tip"
          @click="switchPage('/pages/order/order-list?status=-1')"
        >
          <span>全部订单</span>
          <image
            src="../../static/icons/right.png"
            mode="widthFix"
            class="icon"
          ></image>
        </div>
      </div>
      <div class="bottom">
        <div
          class="order-status"
          @click="switchPage('/pages/order/order-list?status=0')"
        >
          <image
            mode="widthFix"
            class="status-icon"
            src="../../static/icons/unpaid.png"
          ></image>
          <span>待付款</span>
        </div>
        <div
          class="order-status"
          @click="switchPage('/pages/order/order-list?status=1')"
        >
          <image
            mode="widthFix"
            class="status-icon"
            src="../../static/icons/wait_ship.png"
          ></image>
          <span>待寄出</span>
        </div>
        <div
          class="order-status"
          @click="switchPage('/pages/order/order-list?status=2')"
        >
          <image
            mode="widthFix"
            class="status-icon"
            src="../../static/icons/ship.png"
          ></image>
          <span>已寄出</span>
        </div>
      </div>
    </div>
    <view class="divider"> 服务中心 </view>
    <view class="functions">
      <view
        class="function"
        @tap="switchPage('/pages/address/address?type=user')"
      >
        <image
          class="icon"
          mode="widthFix"
          src="../../static/icons/address.png"
        ></image>
        <view class="title">地址管理</view>
      </view>
      <view class="function" @tap="switchPage('/pages/invite/invite-code')">
        <image
          class="icon"
          mode="widthFix"
          src="../../static/icons/recommend.png"
        ></image>
        <view class="title">推荐码</view>
      </view>
      <view class="function" @tap="switchPage('/pages/invite/invite')">
        <image
          class="icon"
          mode="widthFix"
          src="../../static/icons/money.png"
        ></image>
        <view class="title">推广收益</view>
      </view>
      <view
        class="function"
        v-if="isAdmin"
        @tap="switchPage('/pages/statement/statement-create')"
      >
        <image
          class="icon"
          mode="widthFix"
          src="../../static/icons/setting.png"
        ></image>
        <view class="title">协议配置</view>
      </view>
    </view>
  </view>
</template>

<script lang="ts">
import Vue from "vue";
import { createNamespacedHelpers } from "vuex";
const { mapState } = createNamespacedHelpers("user");

export default Vue.extend({
  computed: {
    ...mapState(["userInfo", "isAdmin"]),
  },
  methods: {
    switchPage(url: string) {
      uni.navigateTo({ url });
    },
  },
});
</script>

<style lang="scss" scoped>
.content {
  padding: 64rpx;
  .user-info-section {
    display: flex;
    align-items: center;
    .portrait {
      border-radius: 50%;
      width: 96rpx;
      height: 96rpx;
      margin-right: 24rpx;
    }
    .nickname {
      font-size: 34rpx;
    }
    .info {
      margin-top: 8rpx;
      font-size: 28rpx;
      color: rgba($color: #000000, $alpha: 0.3);
    }
  }
  .divider {
    margin-top: 80rpx;
    margin-bottom: 50rpx;
    font-size: 34rpx;
    font-weight: bold;
    color: rgba($color: #000000, $alpha: 0.9);
    &.divider2 {
      margin-top: 50rpx;
      margin-bottom: 30rpx;
    }
  }
  .order-section {
    .top {
      display: flex;
      justify-content: flex-end;
      margin-bottom: 20rpx;
      .tip {
        font-size: 28rpx;
        color: rgba($color: #000000, $alpha: 0.5);
        display: flex;
        align-items: center;
      }
      .icon {
        width: 35rpx;
      }
    }
    .bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .order-status {
        display: flex;
        flex-direction: column;
        align-items: center;
        image {
          width: 70rpx;
        }
        span {
          font-size: 30rpx;
          color: rgba($color: #000000, $alpha: 0.9);
          margin-top: 20rpx;
        }
      }
    }
  }
  .functions {
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-between;
    .function {
      margin-top: 20rpx;
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-right: 60rpx;
      .title {
        font-size: 30rpx;
        color: rgba($color: #000000, $alpha: 0.9);
        margin-top: 20rpx;
      }
      .icon {
        width: 70rpx;
      }
    }
    .function:last-child {
      margin-right: 0;
    }
  }
}
</style>
